package controller.servletCadastro;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.classDAO.ClienteDAO;
import model.classes.Cliente;
import model.factory.FactoryDAO;

public class ServletCadastroCliente extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5492813010931449448L;
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
	{
		RequestDispatcher rd = null;
		String cnpj = request.getParameter("cnpj");
		String fantasia = request.getParameter("fantasia");
		String razaosocial = request.getParameter("razaosocial");
		
		Cliente cliente = new Cliente();
		
		cliente.setCnpj(cnpj);
		cliente.setFantasia(fantasia);
		cliente.setRazaoSocial(razaosocial);
		
		ClienteDAO clientedao = FactoryDAO.getClienteDAO();
		clientedao.cadastrar(cliente);
		
		rd = request.getRequestDispatcher("/index.jsp");
		try {
			rd.forward(request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
